package org.example.zrccddllljh.Service.Impl;

import org.example.zrccddllljh.Mapper.AnnouncementMapper;
import org.example.zrccddllljh.Pojo.Announcement;
import org.example.zrccddllljh.Service.AnnouncementService;
import org.example.zrccddllljh.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class AnnouncementServiceImpl  implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;
    @Override
    public List<Announcement> list() {
        return   announcementMapper.list();
    }

    @Override
    public void add(Announcement announcement) {
        announcement.setCreateTime(LocalDateTime.now());
        announcement.setUpdateTime(LocalDateTime.now());

        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        announcement.setAdminid(id);
        announcementMapper.add(announcement);
    }

    @Override
    public void upadte(Announcement announcement) {
        announcementMapper.upadte(announcement);
    }

    @Override
    public void deleteById(Integer id) {
        announcementMapper.deleteById(id);
    }
}
